-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve the diagnostics for unused generic params in ty aliases & permit bivariant but constrained params in LTAs #120556
Improve the diagnostics for unused generic params in ty aliases & permit bivariant but constrained params in LTAs #120556
Conversation
) | ||
} else { | ||
format!("consider removing `{param_name}` or referring to it in a field") | ||
let param_name = param.name.ident(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm no longer extracting the Symbol
from the Ident
via param.name.ident().name
since the Display
impl for Ident
accounts for escaping via r#
. This way, we properly display r#if
in type T<r#if> = ();
as r#if
instead of if
.
@@ -10,14 +10,14 @@ error: expected identifier, found reserved identifier `_` | |||
LL | fn bad_infer_fn<_>() {} | |||
| ^ expected identifier, found reserved identifier | |||
|
|||
error[E0392]: parameter `_` is never used | |||
error[E0392]: type parameter `_` is never used |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could add extra code for skipping this error entirely by delaying a bug on _
when checking the “usedness”. Not sure if it'd be worth it though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be very hard to track the expected identifier, found reserved identifier
error all the way into the type system. We'd probably have to add a GenericParamDefKind::Error
to do that. May be worth exploring, but not in this PR
// FIXME: This assumes that elaborated `Sized` bounds come first (which does hold at the | ||
// time of writing). This is a bit fragile since we later use the span to detect elaborated | ||
// `Sized` bounds. If they came last for example, this would break `Trait + /*elab*/Sized` | ||
// since it would overwrite the span of the user-written bound. This could be fixed by | ||
// folding the spans with `Span::to` which requires a bit of effort I think. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't want to deal with this right now but I can try to do so if you'd like me to. I think it'll be a bit nasty to implement though. Consider a hypothetical set of predicates like [<A as TraitA>, <B as TraitB>, /*elab*/<A as Sized>]
(note: we need to merge the spans of the 0th and the 2nd predicate).
Maybe it's actually not that ugly to implement, I just haven't spent any time to think about this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why does it rely on that? the spans differ, so both elaborated and user-written would end up in the hash set
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦 it's a hashmap and this collect relies on the hash map impl overwriting with follow up items of the same key
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems fine to rely on this, there are tests after all
7a4f93d
to
02320b5
Compare
@bors r+ rollup |
🌲 The tree is currently closed for pull requests below priority 100. This pull request will be tested once the tree is reopened. |
…m-diags, r=oli-obk Improve the diagnostics for unused generic parameters * Don't emit two errors (namely E0091 *and* E0392) for unused type parameters on *lazy* type aliases * Fix the diagnostic help message of E0392 for *lazy* type aliases: Don't talk about the “fields” of lazy type aliases (use the term “body” instead) and don't suggest `PhantomData` for them, it doesn't make much sense * Consolidate the diagnostics for E0091 (unused type parameters in type aliases) and E0392 (unused generic parameters due to bivariance) and make it translatable * Still keep the error codes distinct (for now) * Naturally leads to better diagnostics for E0091 r? `@oli-obk` (to ballast your review load :P) or compiler
…m-diags, r=oli-obk Improve the diagnostics for unused generic parameters * Don't emit two errors (namely E0091 *and* E0392) for unused type parameters on *lazy* type aliases * Fix the diagnostic help message of E0392 for *lazy* type aliases: Don't talk about the “fields” of lazy type aliases (use the term “body” instead) and don't suggest `PhantomData` for them, it doesn't make much sense * Consolidate the diagnostics for E0091 (unused type parameters in type aliases) and E0392 (unused generic parameters due to bivariance) and make it translatable * Still keep the error codes distinct (for now) * Naturally leads to better diagnostics for E0091 r? ``@oli-obk`` (to ballast your review load :P) or compiler
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#119759 (Add FileCheck annotations to dataflow-const-prop tests) - rust-lang#120323 (On E0277 be clearer about implicit `Sized` bounds on type params and assoc types) - rust-lang#120473 (Only suggest removal of `as_*` and `to_` conversion methods on E0308) - rust-lang#120520 (Some cleanups around diagnostic levels.) - rust-lang#120540 (add test for try-block-in-match-arm) - rust-lang#120547 (`#![feature(inline_const_pat)]` is no longer incomplete) - rust-lang#120552 (Correctly check `never_type` feature gating) - rust-lang#120555 (put pnkfelix (me) back on the review queue.) - rust-lang#120556 (Improve the diagnostics for unused generic parameters) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#119759 (Add FileCheck annotations to dataflow-const-prop tests) - rust-lang#120323 (On E0277 be clearer about implicit `Sized` bounds on type params and assoc types) - rust-lang#120473 (Only suggest removal of `as_*` and `to_` conversion methods on E0308) - rust-lang#120520 (Some cleanups around diagnostic levels.) - rust-lang#120540 (add test for try-block-in-match-arm) - rust-lang#120547 (`#![feature(inline_const_pat)]` is no longer incomplete) - rust-lang#120552 (Correctly check `never_type` feature gating) - rust-lang#120555 (put pnkfelix (me) back on the review queue.) - rust-lang#120556 (Improve the diagnostics for unused generic parameters) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#119759 (Add FileCheck annotations to dataflow-const-prop tests) - rust-lang#120323 (On E0277 be clearer about implicit `Sized` bounds on type params and assoc types) - rust-lang#120473 (Only suggest removal of `as_*` and `to_` conversion methods on E0308) - rust-lang#120540 (add test for try-block-in-match-arm) - rust-lang#120547 (`#![feature(inline_const_pat)]` is no longer incomplete) - rust-lang#120552 (Correctly check `never_type` feature gating) - rust-lang#120555 (put pnkfelix (me) back on the review queue.) - rust-lang#120556 (Improve the diagnostics for unused generic parameters) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#120556 - fmease:improve-unused-generic-param-diags, r=oli-obk Improve the diagnostics for unused generic parameters * Don't emit two errors (namely E0091 *and* E0392) for unused type parameters on *lazy* type aliases * Fix the diagnostic help message of E0392 for *lazy* type aliases: Don't talk about the “fields” of lazy type aliases (use the term “body” instead) and don't suggest `PhantomData` for them, it doesn't make much sense * Consolidate the diagnostics for E0091 (unused type parameters in type aliases) and E0392 (unused generic parameters due to bivariance) and make it translatable * Still keep the error codes distinct (for now) * Naturally leads to better diagnostics for E0091 r? ```@oli-obk``` (to ballast your review load :P) or compiler
PhantomData
for them, it doesn't make much senseEdit(2024-07-26): This PR starts allowing bivariant but constrained params in lazy type aliases just like in ADTs. E.g.,
type A<T, F> = F where F: Fn() -> T;
(similar tostruct S<T, F>(F) where F: Fn() -> T;
);T
is bivariant but constrained. E0091 for eager type aliases doesn't account for such a thing.r? @oli-obk (to ballast your review load :P) or compiler